#ifndef Client_h__
#define Client_h__

#include "NonCopyable.h"
#include "Singleton.h"
#include "GameMessage.h"

class Client : public NonCopyable
{
private:
	Client();
	friend class Singleton<Client>;
public:
	void SendToServer(GameMessage& gm);
    void RequestIDFromServer();
    bool IsConnected(){return m_connected;}
    void Update();
    void SetID(int id);
	bool ConnectToServer(const std::string& IP, int port);
    bool Listen();
    void ShutDown();
    int GetID(){return m_id;}
    void HasDisconnected(){m_connected = false; m_sock.Close();}
    void PingServer();
    void AcceptPing(int ts);
    void SetTime(int t){m_time = t;}
    void RequestTimeUpdate();
    int GetGameTime(){return m_time;}
    int GetLagTime(){return m_delay;}
    bool IsInitialConnection()
    {
        if(m_initialConnection == 0)
        {
            m_initialConnection++;
            return true;
        }
        return false;
    }
private:
    int m_id;
    Networking::Socket m_sock;
    int m_time;
    int m_delay;
    bool m_connected;
    int m_pingCounter;
    int m_pingStore;
    int m_numPingSent;
	int m_timerCounter;
    int m_initialConnection;
	int m_networkTimeOutCounter;
    
};

typedef Singleton<Client>  TheClient;
#endif // Client_h__
